
const tips = {
  1: '没网！！！',
  1000: '输入参数错误',
  1005: '不正确的开发者key',
  1007: '未找到当前接口',
  0: '点赞成功'
}

const url = ''

export default class Common {
  http(parames) {
    let method = parames.method || "POST"
    let id = wx.getStorageSync('id')
    parames.data.unid = id

    wx.request({
      url: url + parames.url,
      method: method,
      data: parames.data,
      success: (res) => {
        // startsWith endsWith 字符串开头 结尾
        parames.success ? parames.success(res) : ''
      },
      fail: (err) => {
        // this._show_error(1)
      }
    })
  }

  _show_error(error_code) {
    if (!error_code) {
      error_code = 1
    }
    wx.showToast({
      title: tips[error_code],
      icon: 'none',
      duration: 2000,
    })
  }

  throttle(fn, gapTime) {
    if (gapTime == null || gapTime == undefined) {
      gapTime = 1500
    }
    let _lastTime = null
    return function () {
      let _nowTime = + new Date()
      if (_nowTime - _lastTime > gapTime || !_lastTime) {
        fn.apply(this, arguments)  
        _lastTime = _nowTime
      }
    }
  }


}